<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>提现</title>
    <link rel="stylesheet" type="text/css" href="../../../../css/aui/aui.css" />
    <style>
        html,
        body {
            background: #fff;
        }

        #app {
            padding: 1.5rem 2.5rem;
        }

        .btn {
            background: #0689FB;
            width: 100%;
            height: 2rem;
            text-align: center;
            line-height: 2rem;
            color: #fff;
            margin: 2rem auto 0;
            border-radius: 0.2rem;
        }

        .tixian_money {
            text-align: center;
            line-height: 2.5rem;
            font-size: 0.9rem;
        }

        .inp_box {
            height: 2.25rem;
            border: 1px solid #97CCF8;
            padding: 0 0.5rem;
            margin-bottom: 0.5rem;
            color: #777;
        }

        .note {
            font-size: 0.6rem;
            color: #999;
            margin-top: 2rem;
        }

        .layui-form-select dl dd.layui-this {
            background: #eee !important;
            color: #212121;
        }

        .list_wrap {
            width: 100%;
            max-height: 10rem;
            position: absolute;
            top: 7.8rem;
            box-shadow: 0 0 4px #ccc;
            background: #fff;
            padding-bottom: 0.5rem;
            overflow-y: scroll;
            display: none;
        }

        .list_item {
            height: 2.5rem;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 0.7rem;
            border-bottom: 1px solid #eee;
        }

        .list_item img {
            width: 1.5rem;
            margin-right: 0.5rem;
        }

        .bank_card {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .aui-icon-down {
            color: #97CCF8
        }
    </style>
</head>

<body>
    <div id="app">
        <div style="position:relative;">
            <div class="tixian_money">可提现金额：<span style="color:#E90D0D;">￥{{userInfo.wallet_balance}}</span></div>
            <div class='inp_box'>
                <input type="number" v-model="info.order_price" placeholder="请输入提现金额" class="layui-input">
            </div>
            <div class='inp_box bank_card' @click="openSelectBank();">
                <span>{{bank_cards.bank_card}}</span><i class="aui-iconfont aui-icon-down"></i>
            </div>
            <div class='list_wrap'>
                <div class="list_item" v-for="o in list" @click="selectBank(o)">
                    <img :src="bankIcon[o.bank_code]" alt="">{{o.bank_name}} ({{o.bank_card.substr(-4)}})
                </div>
            </div>
        </div>

        <div class="btn" @click="submit()">立即提现</div>

        <div class="note">
            <div>备注：</div>
            <div style="text-indent: 1.2rem;">1.若未绑定银行卡，请先到我的钱包页面绑定银行卡。</div>
            <div style="text-indent: 1.2rem;">2.以100 整数倍提现</div>
        </div>
    </div>
</body>
<script src="../../../../script/api.js" charset="utf-8"></script>
<script src="../../../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../../../script/aui/aui-dialog.js" charset="utf-8"></script>
<script src="../../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../../script/common/check.js" charset="utf-8"></script>
<script src="../../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();

    }

    var vm = new Vue({
        el: "#app",
        data: {
            userInfo: {},
            bank_cards: {
                bank_card: '请选择提现银行卡'
            },
            bankIcon: {
                'BOC': "../../../../image/icon/zhognguo_logo.png",
                'ICBC': "../../../../image/icon/gongshang_logo.png",
                'ABC': "../../../../image/icon/nongye_logo.png",
                'CBC': "../../../../image/icon/jianshe_logo.png",

                'CCB': "../../../../image/icon/jiaotong_logo.png",
                'PSBC': "../../../../image/icon/youzheng_logo.png",
                'CMB': "../../../../image/icon/zhaoshang_logo.png",
                'CIB': "../../../../image/icon/xingye_logo.png",

                'CMBC': "../../../../image/icon/mingsheng_logo.png",
                'CITIC': "../../../../image/icon/zhongxin_logo.png",
                'SPDB': "../../../../image/icon/pufa_logo.png",
            },
            list: [],
            info: {
                user_id: '',
                order_price: '',
                bank_id: '',
                pay_pass: 0
            }
        },
        methods: {
            init() {
                this.userInfo = get_local("userInfo");
                this.info.user_id = this.userInfo.user_id;
                this.getList();
            },
            getList() {
                var that = this;
                var data = {
                    user_id: this.userInfo.user_id,
                };
                _ajax(Config.api.UserBankGetLists, data, function(ret) {
                    if (ret.code === 200) {
                        that.list = ret.data;
                    }
                });
            },
            submit() {
                if (!is_define(this.info.order_price)) {
                    $toast("请输入提现金额");
                    return;
                } else if ((this.info.order_price * 100).toString().indexOf('.') != -1) {
                    $toast('只能精确到分');
                    return;
                } else if (!is_define(this.info.bank_id)) {
                    $toast("请选择提现银行卡");
                    return;
                } else if (this.userInfo.wallet_balance * 100 < this.info.order_price * 100) {
                    $toast('余额不足');
                    return;
                } else if (this.info.order_price < 100) {
                    $toast('提现金额不得少于100元');
                    return;
                } else if (this.info.order_price % 100 != 0) {
                    $toast('提现金额为100的倍数');
                    return;
                }

                var self = this;
                var dialog = new auiDialog({});
                dialog.prompt({
                    title: "支付密码",
                    text: '请输入支付密码',
                    type: 'password',
                    buttons: ['取消', '确定']
                }, function(ret) {
                    if (ret.buttonIndex == 2) {
                        if (ret.text.length != 6) {
                            $toast('请输入六位数密码');
                            return false;
                        }
                        self.info.pay_pass = ret.text;
                        _ajax(Config.api.WithdrawApply, self.info, function(ret) {
                            if (ret.code === 200) {
                                $toast("提现成功");

                                api.execScript({
                                    name: 'main',
                                    frameName: 'my',
                                    script: 'vm.gerUserInfo()'
                                });

                                setTimeout(function() {
                                    close_w();
                                }, 1000);
                            } else {
                                $toast(ret.msgs);
                            }
                        });
                    }
                })

            },
            openSelectBank() {
                if (this.list.length > 0) {
                    $(".list_wrap").show();
                } else {
                    $toast("请添加银行卡后再提现");
                }
            },
            selectBank(o) {
                this.info.bank_id = o.bank_id;
                this.bank_cards.bank_card = o.bank_name + "(" + o.bank_card.substr(-4) + ")";
                $(".list_wrap").hide();
            }
        }
    });
</script>

</html>
